<?

/*	MOD SUPERCLASS
* This class contains all default functionalities for
* the module's public output.
* this can be extended with 4 medio-classes:
*	mod_GROUP				grouping / glue additions
*	mod_MEDIA				image & flash additions
*	mod_OBJECT				multiple content objects additions
*	mod_TEXT				string / search & regexp additions
*					*/

class MODULE extends MOD {
	
	public function get( $id, $grid = null ) {
		global $DB;
		
		$json = self::request_json( $id );
		$json->grid = $grid;
		
		if( $MOD = self::render( $json ))
			return $MOD->output();
	}
	
	/*	Retreive json object */
	public function request_json( $id ) {
		global $DB;
		
		$json = $DB->query_direct( "select json from moddump where ID='$id'" );
		$json = json_decode( $json );
		$json->id = $id;
		
		return $json;
	}
	
	/*	Render mod class */
	public function render ( $vars ) {

		if( $vars->modclass = self::req_mod( $vars->mod ))
			return new $vars->modclass( $vars );
			
		else return null;
	}
	
	/*	Include mod class */
	public function req_mod ( $mod ) {
		
		$modclass	= ( $mod )? camelize( $mod ) : false;
		
		if( !class_exists( $modclass, false ))
			require_once( ( file_exists ($custom = ROOT . ACCOUNT ."/custom.root/modules/$mod/module.php"))?
						$custom : ENGINE_CORE . "modules/$mod/module.php" );
		
		return $modclass;
	}
	

}

?>